"""
doc
"""
from typing import Tuple
from django.db import models
from django.db.models.manager import BaseManager
from django.http import HttpRequest
from django.core.paginator import Paginator


def page(
    request: HttpRequest, objs: BaseManager[models.Model]
) -> Tuple[BaseManager[models.Model], int]:
    """page model list"""
    objs = objs.order_by("-id")
    if request.GET.get("all", None):
        return objs

    _page = int(request.GET.get("page", 1))
    num = min(200, int(request.GET.get("num", 100)))
    p = Paginator(objs, per_page=num)
    return p.get_page(_page).object_list, p.num_pages
